import http from "@/http";

/**
 * @description: 我申请的项目列表，可以指定过滤条件
 */
export const getProjectList = (data: {
  current: number;
  pageSize: number;
  capital?: string;
  field?: string;
  keyword?: string;
  scale?: string;
  stage?: string;
  type?: string;
  tabStatus?: string | number;
}) => {
  const { current, pageSize, ...searchProjectDto } = data;
  return http
    .postReq({
      url: "/api/project/list",
      params: { page: current, size: pageSize },
      data: searchProjectDto,
    })
    .then((res) => {
      const { body, total } = res;
      return {
        list: body,
        total,
      };
    });
};
/**
 * @description: 我审核的项目列表，可以指定过滤条件
 */
export const getApprovalProjectList = (data: {
  current: number;
  pageSize: number;
  capital?: string;
  field?: string;
  keyword?: string;
  scale?: string;
  stage?: string;
  type?: string;
}) => {
  const { current, pageSize, ...searchProjectDto } = data;
  return http
    .postReq({
      url: "/api/project/listApproval",
      params: { page: current, size: pageSize },
      data: searchProjectDto,
    })
    .then((res) => {
      const { body, total } = res;
      return {
        list: body,
        total,
      };
    });
};
/**
 * @description: 项目列表，可以指定过滤条件，后台管理用
 */
export const getAllProjectList = (data: {
  current: number;
  pageSize: number;
  capital?: string;
  field?: string;
  keyword?: string;
  scale?: string;
  stage?: string;
  type?: string;
  tabStatus?: string | number;
}) => {
  const { current, pageSize, tabStatus, ...searchProjectDto } = data;
  return http
    .postReq({
      url:
        "/api/project/listAll" +
        (tabStatus !== undefined ? `/${tabStatus}` : ""),
      params: { page: current, size: pageSize },
      data: searchProjectDto,
    })
    .then((res) => {
      const { body, total } = res;
      return {
        list: body,
        total,
      };
    });
};
/**
 * @description: 项目信息创建
 */
export const createProject = (data: {
  address: string;
  area: string;
  belong: string;
  capital: string;
  city: string;
  contact: string;
  contactInfo: string;
  country: string;
  email: string;
  endDate: string;
  field: string;
  fileId: string;
  intro: string;
  latitude: string;
  longitude: string;
  name: string;
  orgArea: string;
  orgType: string;
  postalCode: string;
  province: string;
  scale: string;
  stage: string;
  startDate: string;
  street: string;
  type: string;
}) => {
  return http
    .postReq({
      url: "/api/project/create",
      data,
    })
    .then((res) => res.body);
};
/**
 * @description: 用于提交项目指标填报资料
 */
export const fillProjectIndicator = (data: {
  formData: string;
  indicatorId: number;
  projectId: number;
}) => {
  return http.postReq({
    url: "/api/project/fillin",
    data,
  });
};
/**
 * @description: 分配项目审核人
 */
export const assignReviewer = (data: {
  approveUserId: number;
  projectId: number;
}) => {
  return http.postReq({
    url: "/api/project/assign",
    data,
  });
};
/**
 * @description: 审核确认项目信息和指标
 */
export const confirmProjectInfo = (projectId: number | string) => {
  return http.getReq({
    url: "/api/project/confirm/" + projectId,
  });
};
/**
 * @description: 项目填报和查看项目指标填报审核信息用
 */
export const getProjectIndicatorDetailById = ({
  indicatorId,
  projectId,
}: {
  indicatorId: string | number;
  projectId: string | number;
}): Promise<{
  id?: number;
  indicatorId?: number; //指标id
  name?: string; //指标名称
  projectId?: number; //项目ID
  status?: number; //指标填报状态
  formDefinition?: string; //表单填报定义
  formData?: string; //表单填报内容
  fillinTime?: string; //填报时间
  fillinUserid?: number; //填报人
  fillinUserName?: string;
  score?: number; //指标评分，百分制
  approvalComments?: string; //评审意见
  approvalSuggests?: string; //评审决策建议
  approvalStatus?: number; //指标评审状态
  approveUserid?: number;
  approvalTime?: number;
  approverUserName?: string; //评审人名
}> => {
  return http
    .getReq({
      url: `/api/project/${projectId}/indicator/${indicatorId}`,
    })
    .then((res) => res.body);
};
/**
 * @description: 项目指标填报资料审核
 */
export const approveProjectIndicator = (data: {
  comments?: string;
  indicatorId: number;
  projectId: number;
  score: number;
  suggestion?: string;
}) => {
  return http.postReq({
    url: "/api/project/approve",
    data,
  });
};
/**
 * @description: 项目指标填报资料审核不通过
 */
export const rejectProjectIndicator = (data: {
  comments?: string;
  indicatorId: number;
  projectId: number;
  score: number;
  suggestion?: string;
}) => {
  return http.postReq({
    url: "/api/project/reject",
    data,
  });
};
/**
 * @description: 项目评审完成后接受评审结果
 */
export const acceptResult = (projectId: string | number) => {
  return http.getReq({
    url: `/api/project/accept/${projectId}`,
  });
};
/**
 * @description: 根据项目id获取项目信息
 */
export const getProjectDetail = (projectId: string | number) => {
  return http
    .getReq({
      url: `/api/project/info/${projectId}`,
    })
    .then((res) => res.body);
};
/**
 * @description: 提交项目填报资料
 */
export const submitFillin = (projectId: string | number) => {
  return http
    .getReq({
      url: `/api/project/submitFillin/${projectId}`,
    })
    .then((res) => res.body);
};
/**
 * @description: 提交项目评审
 */
export const submitApproval = (projectId: string | number) => {
  return http
    .getReq({
      url: `/api/project/submitApproval/${projectId}`,
    })
    .then((res) => res.body);
};
